﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_EditDeliveryArea : ASPXBaseClass
{
    GZ.Entity.EDeliveryArea objDeliveryArea = new GZ.Entity.EDeliveryArea();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["User"].ToString() != "admin")
        {
            Response.Redirect("~/Admin/RedirectLogin.htm");
        }
        if (!IsPostBack)
        {
            BindRpt();
        }
    }

    void BindRpt()
    {
        string Id = GZ.Common.HttpHelper.GetParameter("Id", GZ.Common.HttpHelper.HttpType.GET);
        List<GZ.Entity.EDeliveryArea> list = objDeliveryArea.GetById(Convert.ToInt32(Id));
        GZ.Common.DataBindHelper.BindRepeater(objDeliveryArea.GetDeliveryArea(Convert.ToInt32
    (Id)), this.rptDeliveryArea);
        this.HParentId.Value = Id;
    }


    /// <summary>
    /// 添加事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        if (this.HId.Value.Length > 0)
        {
            GZ.Entity.EDeliveryArea obj = new GZ.Entity.EDeliveryArea();
            obj.DeliveryAreaName = this.txtDeliveryArea.Text;
            obj.ParentId = Convert.ToInt32(this.HParentId.Value);
            obj.OrderValue = Convert.ToInt32(this.txtOrderValue.Text);
            obj.Id = Convert.ToInt32(this.HId.Value);
            if (objDeliveryArea.Edit(obj))
            {
                BindRpt();
                this.txtOrderValue.Text = string.Empty;
                this.txtDeliveryArea.Text = string.Empty;
                this.HId.Value = string.Empty;
                this.btnAdd.Text = "添加";
            }
        }
        else
        {
            GZ.Entity.EDeliveryArea obj = new GZ.Entity.EDeliveryArea();
            obj.DeliveryAreaName = this.txtDeliveryArea.Text;
            obj.ParentId = Convert.ToInt32(this.HParentId.Value);
            obj.OrderValue = Convert.ToInt32(this.txtOrderValue.Text);
            if (objDeliveryArea.Add(obj))
            {
                BindRpt();
                this.txtOrderValue.Text = string.Empty;
                this.txtDeliveryArea.Text = string.Empty;
                this.HId.Value = string.Empty;
            }
        }
    }

    /// <summary>
    /// 行处理事件
    /// </summary>
    /// <param name="source"></param>
    /// <param name="e"></param>
    protected void rptDeliveryArea_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        int Id = Convert.ToInt32(e.CommandArgument);
        if (e.CommandName == "Del")
        {
            if (objDeliveryArea.Del(Id))
            {
                BindRpt();
            }
        }
        if (e.CommandName == "Edit")
        {
            List<GZ.Entity.EDeliveryArea> list = objDeliveryArea.GetById(Id);
            this.txtDeliveryArea.Text = list[0].DeliveryAreaName;
            this.txtOrderValue.Text = list[0].OrderValue.ToString();
            this.HParentId.Value = list[0].ParentId.ToString();
            this.HId.Value = list[0].Id.ToString();
            this.btnAdd.Text = "保存";
        }
    }

    /// <summary>
    /// 退出事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnReturn_Click(object sender, EventArgs e)
    {
        ClientScript.RegisterClientScriptBlock(this.GetType(), "update", "<script>window.opener.location.href=window.opener.location.href;window.close();</script>");
    }
}